package cybertechcebu.task
{
	import cybertechcebu.FTPClient;
	import cybertechcebu.LocalFile;
	import cybertechcebu.RemoteFile;
	import cybertechcebu.enum.FileStatus;

	public class ListDirWithCheckTask extends ListDirTask
	{
		private var fileToCheck:LocalFile;

		public function ListDirWithCheckTask(client:FTPClient, fileToCheck:LocalFile)
		{
			super(client);
			this.fileToCheck = fileToCheck;
		}

		override protected function parseFromListing(listing:String, dir:String):Array
		{
			var list:Array = [];
			var rawList:Array = listing.match(/^.+/gm);
			var i:int = rawList.length;

			while (i--)
			{
				var remoteFile:RemoteFile = parseFromListEntry(rawList[i], dir);

				if (fileToCheck.name == remoteFile.name)
				{
					if (remoteFile.size == fileToCheck.size)
					{
						fileToCheck.status = FileStatus.SUCCESS;
					}
					else
					{
						fileToCheck.status = FileStatus.FAIL;
					}
				}



				list.push(remoteFile);
			}
			return list;
		}

	}
}
